package com.gitee.xqxyxchy.swagger;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.service.VendorExtension;

@Configuration
@ConfigurationProperties(prefix = "swagger")
public class SwaggerConfig {
	
	private String title;
	private String host;
	private String description;
	private String version;
	private String docs = "v2/api-docs";
	private boolean disable = false;
	private String basePackage = "com.gitee.xqxyxchy";
	private String termsOfServiceUrl = "https://gitee.com/xqxyxchy";
	private String contactName = "xqxyxchy";
	private String contactEmail = "xqxyxchy@126.com";
	private String contactUrl = "https://gitee.com/xqxyxchy";
	private Set<StringVendorExtension> stringExtensions = new HashSet<>();
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDocs() {
		return docs;
	}

	public void setDocs(String docs) {
		this.docs = docs;
	}

	public boolean isDisable() {
		return disable;
	}

	public void setDisable(boolean disable) {
		this.disable = disable;
	}

	public String getBasePackage() {
		return basePackage;
	}

	public void setBasePackage(String basePackage) {
		this.basePackage = basePackage;
	}

	public String getTermsOfServiceUrl() {
		return termsOfServiceUrl;
	}

	public void setTermsOfServiceUrl(String termsOfServiceUrl) {
		this.termsOfServiceUrl = termsOfServiceUrl;
	}

	public String getContactName() {
		return contactName;
	}

	public void setContactName(String contactName) {
		this.contactName = contactName;
	}

	public String getContactEmail() {
		return contactEmail;
	}

	public void setContactEmail(String contactEmail) {
		this.contactEmail = contactEmail;
	}

	public String getContactUrl() {
		return contactUrl;
	}

	public void setContactUrl(String contactUrl) {
		this.contactUrl = contactUrl;
	}

	public Set<StringVendorExtension> getStringExtensions() {
		return stringExtensions;
	}

	public void setStringExtensions(Set<StringVendorExtension> stringExtensions) {
		this.stringExtensions = stringExtensions;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	@SuppressWarnings("rawtypes")
	public List<VendorExtension> getExtensions() {
		List<VendorExtension> result = new ArrayList<>();
		if(null == getStringExtensions()) {
			return result;
		}
		
		for(StringVendorExtension stringExtension : getStringExtensions()) {
			result.add(new springfox.documentation.service.StringVendorExtension(stringExtension.getName(), stringExtension.getValue()));
		}
		
		return result;
	}
	
	@Override
	public String toString() {
		return "SwaggerConfig [disable=" + isDisable()  + ", host=" + getHost() + ", basePackage=" + getBasePackage() + "]";
	}
	
}

class StringVendorExtension implements VendorExtension<String> {

	private String name;
	private String value;
	
	public StringVendorExtension() {
		super();
	}

	public StringVendorExtension(String name, String value) {
		super();
		this.name = name;
		this.value = value;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getValue() {
		return value;
	}
	
}
